'use client';

import { orderStatusValues } from '@/lib/db/schema/enum';
import { userOrderSearchSchema } from '@/service/query/schema/order';
import { orderStatusMap } from '@/service/type/order';
import DateRangePicker from '../common/date-range-picker';
import MultiSelector from '../common/multi-selector';
import SearchFilter from '../common/search-filter';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '../ui/dialog';

export default function OrderSearch() {
  return (
    <Dialog>
      <DialogTrigger className="flex items-center gap-1">
        <span className="i-ri-search-line" />
        搜索
      </DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>搜索订单</DialogTitle>
          <DialogDescription className="hidden" />
        </DialogHeader>
        <SearchFilter
          formSchema={userOrderSearchSchema}
          defaultValues={{
            shopName: '',
            status: [],
            dateRange: undefined,
          }}
          formItems={[
            { name: 'shopName', label: '店铺名称' },
            {
              name: 'status',
              label: '订单状态',
              inputComp: MultiSelector,
              options: {
                items: orderStatusValues.map((i) => ({
                  label: orderStatusMap[i],
                  value: i,
                })),
              },
            },
            {
              name: 'dateRange',
              label: '订单日期',
              inputComp: DateRangePicker,
            },
          ]}
        />
      </DialogContent>
    </Dialog>
  );
}
